/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights
 * reserved. <a>http://www.cqcis.com</a>
 */
package com.cq.bd.service.impl;

import java.util.List;
import java.util.Map;

import com.cq.base.domain.Page;
import com.cq.bd.dao.SRoleDao;
import com.cq.bd.dao.SRoleFunctionDao;
import com.cq.bd.domain.SRole;
import com.cq.bd.domain.SRoleFunction;
import com.cq.bd.service.RoleService;

/**
 * 角色管理服务
 * 
 * @author huangmy
 * @date   2009-10-5
 */
public class RoleServiceImpl implements RoleService {
    private SRoleDao sRoleDao;
    private SRoleFunctionDao sRoleFunctionDao;
    
    public SRole doGetRole(Long roleId) {
        return this.sRoleDao.get(roleId);
    }
    
    public void doDeleteRoleFuncs(List<SRoleFunction> roleFuncs) {
        for (SRoleFunction sf : roleFuncs) {
            this.doRemoveRoleFunc(sf);
        }
    }
    
    public void doDeleteRole(Long roleId) {
        SRole s = this.sRoleDao.get(roleId);
        if (s != null) {
            this.sRoleDao.remove(s);
        }
    }
    
    public void doCreateRoleFuncs(List<SRoleFunction> roleFuncs) {
        for (SRoleFunction sf : roleFuncs) {
            this.doCreateRoleFunc(sf);
        }
    }
    
    public List<SRoleFunction> doGetFuncsOfRole(Long roleId) {
        return this.sRoleFunctionDao.findBy("roleId", roleId);
    }
    
    public Page pageRoles(Map<String, String> filter, Map<String, String> like, Map<String, String> sort, int pageNo,
            int pageSize) {
        return this.sRoleDao.pagedQuery(filter, like, sort, pageNo, pageSize);
    }
    
    @SuppressWarnings("unchecked")
    public List<SRoleFunction> doGetRoleFuncs(Long roleId) {
        return this.sRoleFunctionDao.find("from SRoleFunction where roleId=?", roleId);
    }
    
    public void doCreateRole(SRole role) {
        this.sRoleDao.create(role);
    }
    
    public List<SRole> doGetRoles() {
        return this.sRoleDao.list();
    }
    
    public void doUpdateRole(SRole role) {
        this.sRoleDao.update(role);
    }
    
    public void doCreateRoleFunc(SRoleFunction roleFunc) {
        this.sRoleFunctionDao.create(roleFunc);
    }
    
    public void doRemoveRoleFunc(SRoleFunction roleFunc) {
        this.sRoleFunctionDao.remove(roleFunc);
    }

    public void setSRoleDao(SRoleDao roleDao) {
        sRoleDao = roleDao;
    }

    public void setSRoleFunctionDao(SRoleFunctionDao roleFunctionDao) {
        sRoleFunctionDao = roleFunctionDao;
    }

}
